package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.constant.MessageConstant;
import com.atguigu.entry.PageResult;
import com.atguigu.entry.QueryPageBean;
import com.atguigu.entry.Result;
import com.atguigu.pojo.TravelGroup;
import com.atguigu.service.TravelGroupService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/travelgroup")
@RestController
public class TravelGroupController {

    @Reference
    private TravelGroupService travelGroupService;

    //查询所有
    @RequestMapping("/findAll")
    public Result findAll() {
        // 查询所有的跟团游
        List<TravelGroup> lists = travelGroupService.findAll();
        if (lists != null && lists.size() > 0) {
            Result result = new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, lists);
            return result;
        }
        return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);

    }




    // 编辑跟团游（返回 public Result(boolean flag, String message)）
    @RequestMapping("/edit")
    public Result edit(Integer[] travelItemIds,@RequestBody TravelGroup travelGroup ){
        travelGroupService.edit(travelItemIds,travelGroup);
        return new Result(true,MessageConstant.EDIT_TRAVELGROUP_SUCCESS);
    }

    @RequestMapping("/findTravelItemIdByTravelgroupId")
    public List<Integer> findTravelItemIdByTravelgroupId(Integer id) {
        List<Integer> lists = travelGroupService.findTravelItemIdByTravelgroupId(id);
        return lists;
    }

    @RequestMapping("/findById")
    public Result findById(Integer id) {
        TravelGroup travelGroup = travelGroupService.findById(id);
        return new Result(true, MessageConstant.QUERY_TRAVELGROUP_SUCCESS, travelGroup);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody TravelGroup travelGroup,Integer[] travelItemIds) {
        travelGroupService.add(travelGroup, travelItemIds);
        return new Result(true, MessageConstant.ADD_TRAVELGROUP_SUCCESS);
    }

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = travelGroupService.findPage(queryPageBean);
        return pageResult;
    }

}
